<?php

declare(strict_types=1);

namespace App\Controller;

use App\Constants\ErrorCode;
use App\Exception\BusinessException;
use App\Service\ShopService;
use Hyperf\DbConnection\Db;
use Hyperf\Validation\Rule;
use Psr\Http\Message\ResponseInterface;
use Hyperf\Di\Annotation\Inject;
use Swoole\Exception;

/**
 * 店铺管理
 * Class ShopController
 * @package App\Controller
 */
class ShopController extends AbstractController
{

    /**
     * @Inject
     * @var ShopService
     */
    private $shopService;

    /**
     * 获取登录用户信息
     * @return int
     */
    public function get_user_id(): int
    {
        $user_id = (int)$this->request->getHeaderLine('admin_id') ?? 0;
        if (empty($user_id)) {
            throw new BusinessException(ErrorCode::NORMAL_ERROR, '未登录，请先登录');
        }
        return $user_id;
    }

    /**
     * 美食商家
     * @return ResponseInterface
     */
    public function food_list(): ResponseInterface
    {
        $request_p =  $this->request->all();
        $data = $this->shopService->food_list($request_p);
        ;
        return $this->jsonResponse->success($this->paginate($data),'美食店铺列表');
    }

    /**
     * 电商商铺列表
     * @return ResponseInterface
     */
    public function list(): ResponseInterface
    {
        $request_p =  $this->request->all();
        $data = $this->shopService->shop_list($request_p);
        return $this->jsonResponse->success($this->paginate($data),'电商店铺列表');
    }


}